package cn.icanci.ladybird.service.impl;

import cn.icanci.ladybird.dao.TicketDetailsDao;
import cn.icanci.ladybird.pojo.dto.UserClassDetailsDto;
import cn.icanci.ladybird.pojo.entity.TicketDetails;
import cn.icanci.ladybird.service.TicketDetailsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TicketDetails)表服务实现类
 *
 * @author makejava
 * @since 2020-09-29 20:43:48
 */
@Service("ticketDetailsService")
public class TicketDetailsServiceImpl implements TicketDetailsService {
    @Resource
    private TicketDetailsDao ticketDetailsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param ticketDetailsId 主键
     * @return 实例对象
     */
    @Override
    public TicketDetails queryById(Long ticketDetailsId) {
        return this.ticketDetailsDao.queryById(ticketDetailsId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<TicketDetails> queryAllByLimit(int offset, int limit) {
        return this.ticketDetailsDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param ticketDetails 实例对象
     * @return 实例对象
     */
    @Override
    public TicketDetails insert(TicketDetails ticketDetails) {
        this.ticketDetailsDao.insert(ticketDetails);
        return ticketDetails;
    }

    /**
     * 修改数据
     *
     * @param ticketDetails 实例对象
     * @return 实例对象
     */
    @Override
    public TicketDetails update(TicketDetails ticketDetails) {
        this.ticketDetailsDao.update(ticketDetails);
        return this.queryById(ticketDetails.getTicketDetailsId());
    }

    /**
     * 通过主键删除数据
     *
     * @param ticketDetailsId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long ticketDetailsId) {
        return this.ticketDetailsDao.deleteById(ticketDetailsId) > 0;
    }

    @Override
    public TicketDetails queryOneByWeight() {
        return this.ticketDetailsDao.queryOneByWeight();
    }

    @Override
    public List<TicketDetails> queryManyByWeight(int offset, int limit) {
        return this.ticketDetailsDao.queryManyByWeight(offset, limit);
    }

    @Override
    public List<TicketDetails> queryManyByWeightAndAdmin(int offset, int limit) {
        return this.ticketDetailsDao.queryManyByWeightAndAdmin(offset, limit);
    }

    @Override
    public List<TicketDetails> queryManyByWeightUp(int offset, int limit) {
        return this.ticketDetailsDao.queryManyByWeightUp(offset, limit);
    }

    @Override
    public List<TicketDetails> queryManyByWeightAndCreateTime(int offset, int limit) {
        return this.ticketDetailsDao.queryManyByWeightAndCreateTime(offset, limit);
    }

    @Override
    public List<TicketDetails> queryManyByWeightAndCreateTimeUp(int offset, int limit) {
        return this.ticketDetailsDao.queryManyByWeightAndCreateTimeUp(offset, limit);
    }

    @Override
    public PageInfo<TicketDetails> queryAllByNotObject(Integer pageNum, Integer pageSize) {
        // 分页
        // pageNum：当前页数   pageSize：当前页需要显示的数量
        // 只要有一个没有传值，那么默认就是首页，然后设置为首页
        if (null == pageNum || null == pageSize) {
            pageNum = 1;
            pageSize = 6;
        }
        // 写在查询的前面
        PageHelper.startPage(pageNum, pageSize);
        // 查询
        List<TicketDetails> ticketDetails = this.ticketDetailsDao.queryAllByNotObject();
        // 把查询的结果封装到 PageInfo
        PageInfo<TicketDetails> ticketDetailsPageInfo = new PageInfo<>(ticketDetails);
        System.out.println(ticketDetails.size());
        return ticketDetailsPageInfo;
    }

    @Override
    public List<TicketDetails> queryByKill(int offset, int limit) {
        return ticketDetailsDao.queryByKill(offset,limit);
    }

    @Override
    public PageInfo<UserClassDetailsDto> queryAllBySearch(String search,Integer pageNum,Integer pageSize) {
        if (null == pageNum || null == pageSize) {
            pageNum = 1;
            pageSize = 6;
        }
        // 写在查询的前面
        PageHelper.startPage(pageNum, pageSize);
        List<UserClassDetailsDto> userClassDetailsDtos = this.ticketDetailsDao.queryAllBySearch(search);
        PageInfo<UserClassDetailsDto> userClassDetailsDtoPageInfo = new PageInfo<>(userClassDetailsDtos);
        return userClassDetailsDtoPageInfo;
    }

    @Override
    public List<UserClassDetailsDto> queryTicketDetailsByCenter() {
        return ticketDetailsDao.queryTicketDetailsByCenter();
    }

    @Override
    public List<UserClassDetailsDto> queryTicketDetailsByCenterUp() {
        return ticketDetailsDao.queryTicketDetailsByCenterUp();
    }

    @Override
    public List<UserClassDetailsDto> queryTicketDetailsByCenterCreatTime() {
        return ticketDetailsDao.queryTicketDetailsByCenterCreatTime();
    }

    @Override
    public List<UserClassDetailsDto> queryTicketDetailsByCenterCreatTimeDown() {
        return ticketDetailsDao.queryTicketDetailsByCenterCreatTimeDown();
    }

    @Override
    public List<UserClassDetailsDto> queryTicketDetailsAll() {
        return ticketDetailsDao.queryTicketDetailsAll();
    }
}